package me.itsoo.artemis.framework.core.converter;

import lombok.extern.slf4j.Slf4j;

/**
 * CharacterTypeConvertor
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/18
 */
@Slf4j
public class CharacterTypeConvertor implements TypeConvertor {

    @Override
    public Object convertIfNecessary(Object value) {
        if (value == null) {
            return null;
        }

        if (value instanceof Character) {
            return value;
        }

        if (value instanceof String) {
            final String str = (String) value;
            return str.isEmpty() ? null : str.charAt(0);
        }

        return null;
    }
}
